<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>产品列表</title>
</head>
<body>
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<form class="layui-form">
	<div class="layui-inline">
		<label class="layui-form-label">产品名称：</label>
	    <div class="layui-input-inline">
	         <select name="productId" id="productIdSelect">
	             <option value="">--请选择--</option>
	             <option value="0" th:each="product:${productList}" th:value="${product.id}" th:text="${product.name}"></option>
	         </select>
	    </div>
	</div>
<!--    <div class="layui-inline"> -->
<!--    <label class="layui-form-label">手机号：</label> -->
<!--    <div class="layui-input-inline"> -->
<!-- 		<input type="text" name="mobile" id="mobile" autocomplete="off" placeholder="请输入手机号" class="layui-input"> -->
<!-- 	</div> -->
<!-- 	</div> -->
	<div class="layui-inline">
   <label class="layui-form-label">申请人：</label>
   <div class="layui-input-inline">
		<input type="text" name="applyPeopleName" id="applyPeopleName" autocomplete="off" placeholder="请输入申请人" class="layui-input">
	</div>
	</div>
    <div class="layui-inline">
			 <button class="layui-btn" data-type="reload" id="searchButton" onclick="return search();">搜索</button>
    </div>
          <br>
<!-- 	  <div style="margin-left: 5px;"> -->
<!-- 	  		  <br>	 -->
<!-- 	          <button class="layui-btn layuiadmin-btn-replys" onclick="return sendNoticeSMS();">发送余额不足提示短信</button> -->
<!-- 	  </div>         -->
</form>
<table class="layui-hide" id="appUserProductList"  lay-filter="appUserProductList"></table>
<script type="text/javascript">
var table;
var layer;
layui.use(['table'], function(){
	layer=layui.layer;
	  table = layui.table;
	  tableIns = initTable(table);
	//监听行工具事件
	  table.on('tool(appUserProductList)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'del'){
	    	layer.confirm('确认要删除该产品吗，删除后将无法恢复', {
	    		  btn: ['确认','取消'] //按钮
	    		}, function(){
	    		  var deleteResult = ajaxAction("/product/deleteProduct",{id:data.id});
	    		  if(deleteResult){
	    			  search("删除成功");
	    		  }else{
	    			  layer.msg('删除失败', {icon: 5});
	    		  }
	    		});
	    } else if(obj.event === 'edit'){
	    	toUpdate(data.id);
	    }
	  });
});

function initTable(){
	table.render({
	    elem: '#appUserProductList',
	    url:'/appUserProduct/listData',
	    cellMinWidth: 90,
	    cols:[
		    	[
		    	  {type : 'checkbox',field : 'id'}, 	
			      {field:'applyPeopleName' ,title: '申请人'},
			      {field:'productName', title: '产品名称'},
			      {field:'mobile', title: '用户手机号'},
			      {field:'type',title: '类型',templet:function(value){
			    	  if(value.type==1){
			    		  return "个人";
			    	  }else{
			    		  return "家人";
			    	  }
			      	}
			      },
			      {field:'amount', title: '余额'},
			      {
						field : 'applyDate',
						title : '申请时间',
						sort : true,
						fixed : false,
						templet : '<div>{{ formatDate(d.applyDate)}}</div>'
				  },
			      {field:'observationPeriodStatus', title: '观察期进度'},
			      {field:'totalDays', title: '观察天数'},
			      {field:'areaName', title: '所属区域'}
// 			      {field:'sendSmsCount', title: '发送次数'}
		    	]
	    ],page: true,
	    limit:8,
	    where: {
		    'productId':$("#productIdSelect").val(),
// 		    'mobile':$("#mobile").val(),
		    'applyPeopleName':$("#applyPeopleName").val()
	    },
	    id: 'reloadTable'
	  });
}


	
	function search(sender){
		var productId = $('#productIdSelect');
// 		var mobile = $("#mobile").val();
		var applyPeopleName = $("#applyPeopleName").val();
	      //执行重载
	      table.reload('reloadTable', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	        	productId: productId.val(),
// 	        	mobile:mobile,
	        	applyPeopleName:applyPeopleName
	        }
	      });
	      if(!isNull(sender)){
	    	  layMsg(sender,2000);
	      }
	      return false;
	}
	
	
	
	function  sendNoticeSMS(){
		var checkList = table.checkStatus('reloadTable').data;
		if (checkList.length == 0) {
			layMsg("请选择一条数据", 2000);
			return false;
		}
		var id = "";
		for(var i=0;i<checkList.length;i++){
			if(i>0){
				ids+=',';
			}
			ids+=checkList[i].id;
		}
		$.post("/")
		return false;
	}
	
</script>
<style>
.layui-table-cell{
    height:23px;
    line-height:23px;
}
</style>
</body>
</html>